package presencial2011;

import java.util.Scanner;

public class PruebaNueveAlberto {

	private static int num(char ch) {
		int sol = 0;
		if (ch < 58) {
			sol = ch - 48;
		} else {
			sol = ch - 55;
		}
		return sol;
	}

	private static int resumen(int base, String s) {
		int sol = 0;
		for (int i = 0; i < s.length(); i++) {
			sol += num(s.charAt(i));
			if (sol >= (base - 1)) {
				sol -= (base - 1);
			}
		}
		return sol;
	}

	private static int resumen(int base, int i) {
		int sol = i;
		while (sol >= (base - 1)) {
			sol -= base - 1;
		}
		return sol;
	}

	private static String prueba(int base, String D, String d, String c,
			String r) {
		String sol;
		if (
				resumen(base, D) != 
				resumen(base,
						resumen(base, 
								resumen(base, d) * 
								resumen(base, c)
								)
						+ 
						resumen(base, r)
						)
			) {
			sol = "INCORRECTO";
		} else {
			sol = "POSIBLEMENTE CORRECTO";
		}

		return sol;
	}

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long casosPrueba = in.nextLong();
		for (long vueltas = 0; vueltas < casosPrueba; vueltas++) {
			int base = in.nextInt();
			String D = in.next();
			String d = in.next();
			String c = in.next();
			String r = in.next();
			System.out.println(prueba(base, D, d, c, r));
		}
	}

}
